local skel = fk.CreateSkill {
  name = "emo__fanhun",
  tags = {Skill.Compulsory},
}

skel:addEffect(fk.EnterDying, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local suits, ids = {}, {}
    for _, id in ipairs(player:getPile("emo__DeadButterfly&")) do
      table.insertIfNeed(suits, Fk:getCardById(id).suit)
    end
    for _, id in ipairs(room.draw_pile) do
      if #suits >= 4 then break end
      if Fk:getCardById(id).suit ~= Card.NoSuit then
        if table.insertIfNeed(suits, Fk:getCardById(id).suit) then
          table.insert(ids, id)
        end
      end
    end
    if #ids > 0 then
      player:addToPile("emo__DeadButterfly&", ids, true, skel.name)
    end
    local e = room.logic:getCurrentEvent():findParent(GameEvent.Dying)
    if e and e.parent and e.parent.event == GameEvent.ChangeHp and e.parent.data.reason == "loseHp" then
      room:recover { num = player.maxHp - player.hp, skillName = skel.name, who = player, recoverBy = player }
    end
  end,
})


Fk:loadTranslationTable{
  ["emo__fanhun"] = "反魂",
  [":emo__fanhun"] = "锁定技，每当你进入濒死状态时，将“蝶”补至四种花色，若是因失去体力而进入濒死状态，你回复所有体力。",
}


return skel
